package com.restaurantonlineorder.oauth.handler;

import com.restaurantonlineorder.oauth.utils.ResponseUtil;
import com.restaurantonlineorder.response.BaseResult;
import com.restaurantonlineorder.response.BaseResultCode;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 熊宇
 * @date 2022/7/20 22:57
 * @description 认证异常处理
 */

@Component
public class OauthAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        ResponseUtil.sendMessage(response, BaseResult.failure(BaseResultCode.USER_NOT_LOGGED_IN));
    }
}
